using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DealerPlatform.Domain;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;

namespace DealerPlatform.Service.ProductApp
{
    public partial class ProductService
    {
        public async Task<List<ProductPhoto>> GetProductPhotosByProductNo(params string[] productNos)
        {
            // 使用参数化查询构建 SQL 查询
            var query = $@"SELECT * FROM ProductPhotos 
                            WHERE ProductNo IN ({string.Join(',', productNos.Select((_, i) => $"@p{i}"))})";

            // 执行查询并获取结果
            var photos = context.ProductPhotos
            .FromSqlRaw(query, productNos.Select((num, i) => new SqlParameter($"@p{i}", num)).ToArray())
            .ToList();


            // string productNos2 = $"'{string.Join("','",productNos)}'"; 
            // FormattableString sql = $"select * from ProductPhotos where ProductNo in ({productNos2})";
            // List<ProductPhoto> photos = await context.ProductPhotos.FromSqlInterpolated(sql).ToListAsync();
            // FormattableString sql2 = $"select * from ProductPhotos where ProductNo in (' WJJZZDB',' WJJZZDB1',' WJJZZDB10',' WJJZZDB11',' WJJZZDB12',' WJJZZDB13',' WJJZZDB14',' WJJZZDB15',' WJJZZDB16',' WJJZZDB17',' WJJZZDB18',' WJJZZDB19',' WJJZZDB2',' WJJZZDB20',' WJJZZDB21',' WJJZZDB3',' WJJZZDB4',' WJJZZDB5',' WJJZZDB6',' WJJZZDB7',' WJJZZDB8',' WJJZZDB9',' WJJZZDBB',' WJJZZDBBB',' WJJZZDBBN',' WJJZZDBE',' WJJZZDBF',' WJJZZDBG',' WJJZZDBH',' WJJZZDBI')";
            // List<ProductPhoto> photos2 = await context.ProductPhotos.FromSqlInterpolated(sql2).ToListAsync();
            return photos;
            // return await context.ProductPhotos.Where(p => productNos.Contains(p.ProductNo)).ToListAsync();
            return await productPhotoRepo.GetListAsync(m => productNos.Contains(m.ProductNo));
        }
    }
}